﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Profile;

namespace WebSite.admin.order
{
    public partial class ordera : BaseAdmin
    {
        // Fields

        public string cardprice = "0";
        public string carmsg = "";

        protected Label paytime;

        public string sumprice = "0";

        public string totalprice = "0";

        // Methods
        private void Bind()
        {
            string sql = "select top 1 * from DB_Shopconfig where shopid=1";
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                table.Rows[0]["ordercopy"].ToString();
            }
            string str2 = re.replace(base.Request.QueryString["oid"]);
            string str3 = "select * from DB_order where orderid in (" + str2 + ")";
            DataTable table2 = new DataTable();
            table2 = SQLAccess.GreatDs(str3).Tables[0];
            if (table2.Rows.Count > 0)
            {
                this.memberid.Text = table2.Rows[0]["cname"].ToString();
                foreach (DataRow row in table2.Rows)
                {
                    DataTable table3 = SQLAccess.GreatDs("select DB_Car.carid,DB_Car.pronum,DB_Car.price,DB_Car.sumprice,DB_Car.contents,DB_Shoppro.typeid,DB_Shoppro.proname,DB_Shoppro.proprice1,DB_Shoppro.propic2,DB_Shoppro.proid  from DB_Car inner join DB_Shoppro on DB_Car.productid=DB_Shoppro.proid where DB_Car.flag=1 and DB_Car.orderid=" + row["orderid"].ToString() + "").Tables[0];
                    if (table3.Rows.Count > 0)
                    {
                        foreach (DataRow row2 in table3.Rows)
                        {
                            this.sumprice = string.Format("{0:f}", Convert.ToSingle(this.sumprice) + Convert.ToSingle(row2["sumprice"]));
                            this.carmsg = this.carmsg + "<tr bgcolor='#ffffff'>";
                            string carmsg = this.carmsg;
                            this.carmsg = carmsg + "<td width='25%' align='center'><a href='/cn/products_details.aspx?tid=" + row2["typeid"].ToString() + "&pid=" + row2["proid"].ToString() + "' target=_blank><img src='/uploadfile/product/" + row2["propic2"].ToString() + "' align='middle' border='0' /></a></td> ";
                            string str10 = this.carmsg;
                            this.carmsg = str10 + "<td><font style='FONT-WEIGHT: bold' color='#339900'>" + row2["proname"].ToString() + "</font> &nbsp;<br/>" + row2["contents"].ToString() + "</td>";
                            this.carmsg = this.carmsg + "<td width='20%' align='middle'>" + string.Format("{0:f}", row2["price"]) + " 元</td>";
                            this.carmsg = this.carmsg + "<td width='10%' align='middle'>" + row2["pronum"].ToString() + "</td>";
                            this.carmsg = this.carmsg + "<td width='20%' align='middle'>" + string.Format("{0:f}", row2["sumprice"]) + "元</td>";
                            this.carmsg = this.carmsg + "</tr>";
                        }
                    }
                    this.ordertime.Text = row["ordertime"].ToString();
                    string str5 = "select * from DB_member where memberid=" + row["memberid"].ToString() + " and isnull(flag,0)!=2 ";
                    new DataTable();
                    DataTable table1 = SQLAccess.GreatDs(str5).Tables[0];
                    string str6 = "select * from DB_Pay where payid=" + row["pay"].ToString() + "";
                    DataTable table4 = new DataTable();
                    table4 = SQLAccess.GreatDs(str6).Tables[0];
                    if (table4.Rows.Count > 0)
                    {
                        this.pay.Text = this.pay.Text != "" ? this.pay.Text + ";" + table4.Rows[0]["payname"].ToString() : table4.Rows[0]["payname"].ToString(); 
                        //this.payprice = table4.Rows[0]["pay"].ToString();
                    }
                    else
                    {
                        this.pay.Text = "";
                    }
                    string str7 = "select * from DB_Shipping where shippingid=" + row["ship"].ToString() + "";
                    DataTable table5 = new DataTable();
                    table5 = SQLAccess.GreatDs(str7).Tables[0];
                    if (table5.Rows.Count > 0)
                    {
                        this.ship.Text = table5.Rows[0]["shippingname"].ToString();
                       // this.shiprice = table5.Rows[0]["shippingpay"].ToString();
                    }
                    else
                    {
                        this.ship.Text = "";
                    }
                    this.ordercode.Text = row["ordercode"].ToString();
                    this.address.Text = row["address1"].ToString();
                    this.cname.Text = row["cname1"].ToString();
                    this.post.Text = row["post1"].ToString();
                    this.tel.Text = row["tel1"].ToString();
                    this.sendTime.Text = row["sendDate"].ToString();
                    this.orderno.Text = row["orderscore"].ToString();
                    this.lblContent1.Text = row["content1"].ToString();
                    if (row["scoreprice"].ToString() != "0")
                    {
                        this.paytime.Text = "积分支付：" + row["scoreprice"].ToString();
                     //   this.scoreprice = row["scoreprice"].ToString();
                    }
                    else
                    {
                        this.paytime.Text = "未使用积分";
                    }
                    if ((row["cardid"].ToString() != "0") && (row["cardprice"].ToString() != "0"))
                    {
                        DataTable table6 = SQLAccess.GreatDs("select cardcode from DB_Card where cardid=" + row["cardid"].ToString() + "").Tables[0];
                        if (table6.Rows.Count > 0)
                        {
                            this.shiptime.Text = "礼品卡卡号：" + table6.Rows[0]["cardcode"].ToString() + " 支付金额：" + row["cardprice"].ToString();
                            this.cardprice = row["cardprice"].ToString();
                        }
                        else
                        {
                            this.shiptime.Text = "";
                        }
                    }
                    this.totalprice = string.Format("{0:f}", (Convert.ToSingle(this.sumprice)  - Convert.ToSingle(this.cardprice))) ;
                    this.times.Text = DateTime.Now.ToString();
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
    
            if (!base.IsPostBack && (base.Request.QueryString["oid"] != null))
            {
                this.Bind();
            }
        }


    }
}